package com.yyx.lgb.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyx.lgb.manager.mapper.SysRoleMapper;
import com.yyx.lgb.manager.mapper.SysRoleUserMapper;
import com.yyx.lgb.manager.service.SysRoleService;
import com.yyx.lgb.model.dto.system.SysRoleDto;
import com.yyx.lgb.model.entity.system.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: SysRoleServiceImpl
 * Package: com.yyx.lgb.manager.service.impl
 * Description:
 *
 * @Author: yyx
 * @Create: 2025/8/1 - 10:49
 */
@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;
    @Autowired
    private SysRoleUserMapper sysRoleUserMapper;
    @Override
    public PageInfo<SysRole> findByPage(SysRoleDto sysRoleDto, Integer pageNum, Integer pageSize) {

        //设置分页
        PageHelper.startPage(pageNum,pageSize);
        //根据条件查询数据
        List<SysRole> sysRoleList = sysRoleMapper.findByPage(sysRoleDto) ;
        PageInfo<SysRole> pageInfo = new PageInfo(sysRoleList) ;
        return pageInfo;
    }

    @Override
    public void saveSysRole(SysRole sysRole) {
        sysRoleMapper.saveSysRole(sysRole) ;
    }

    @Override
    public void updateSysRole(SysRole sysRole) {
        sysRoleMapper.updateSysRole(sysRole);
    }

    @Override
    public void deleteById(Long roleId) {
        sysRoleMapper.deleteById(roleId);
    }


//查询所有角色
        @Override
        public Map<String, Object> findAllRoles(Long userId) {
            //1 查询所有角色
            List<SysRole> sysRoleList = sysRoleMapper.findAllRoles() ;

            //TODO 2 分配过的角色列表

         List<Long> sysRoles=   sysRoleUserMapper.findSysUserRoleById(userId);

            Map<String , Object> resultMap = new HashMap<>() ;
            resultMap.put("allRolesList" , sysRoleList) ;
            resultMap.put("sysUserRoles",sysRoles);
            return resultMap;
    }
}
